package gaml.java.serializer.primitive;

import gaml.error.GamlException;
import gaml.java.ClassSerializer;
import gaml.yaml.ScalarNode;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;

/**
 * Float from yaml node
 * yaml node from Float
 * @author shnireck
 *
 */
public class FloatSerializer implements ClassSerializer <Float> {

	@Override
	public Class <Float> getObjectClass () { return Float.class; }

	@Override
	public boolean noAnchor () { return true; }
	
	@Override
	public Float restore (YamlNode node, Float object, YamlAnchorCodeStore anchors) { return Float.parseFloat (node.getValue ().trim ()); }

	@Override
	public YamlNode serialize (YamlNode node, Float obj, YamlAnchorObjectStore anchors) { return new ScalarNode (node.getParent ()).setValue (obj.toString ()); }

	@Override
	public YamlNode createNode (YamlNode parent) { return new ScalarNode (parent); }

	@Override
	public Float createObject () throws GamlException { return null; }
}
